﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;

namespace STT.Business
{
    public class BTbCap
    {
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbCap_SelectAll", null);
            return all;
        }
        public static DataTable SelectAll1()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbCap_SelectAll1", null);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbCap OTbCap)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenCap", OTbCap.TenCap);
            pr[1] = new SqlParameter(@"TrangThai", OTbCap.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbCap_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbCap OTbCap)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaCap", OTbCap.MaCap);
            pr[1] = new SqlParameter(@"TenCap", OTbCap.TenCap);
            pr[2] = new SqlParameter(@"TrangThai", OTbCap.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbCap_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(int MaCap)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaCap", MaCap);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbCap_Delete", pr);
        }
        //-----------------------------------------------------------//

        public static bool KiemTraDuLieu_Sua(ETbCap Cap)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenCap", Cap.TenCap);
            pr[1] = new SqlParameter(@"MaCap", Cap.MaCap);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbCap_KiemTraDuLieu_Sua", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
//-----------------------------------------------------------//

        public static bool KiemTraDuLieu(ETbCap Cap)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenCap", Cap.TenCap);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbCap_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        public static bool KiemTraMaCap(ETbCap Cap)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaCap", Cap.MaCap);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbCap_KiemTraMaCap", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
//-----------------------------------------------------------//
        public static DataTable SearchCap(ETbCap Cap)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenCap", Cap.TenCap);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbCap_Search", pr);
            return all;
        }
//-----------------------------------------------------------//
    }
}